/*
 * @Author: Olivia
 * @Date: 2022-02-01 12:29:34
 * @LastEditTime: 2022-06-28 21:39:16
 * @FilePath: \toutiao-m\src\store\index.js
 * @custom_string_Olivia: Less is more
 */
import Vue from 'vue'
import Vuex from 'vuex'
import { getItem, setItem } from '@/utils/storage'

Vue.use(Vuex)

const TOKEN_KEY = 'TT_USER'
export default new Vuex.Store({
  state: {
    //   一个对象，存储当前登录用户信息（token等数据）
    user: getItem(TOKEN_KEY)
  },
  mutations: {
    setUser (state, data) {
      state.user = data
      //   为了防止刷新丢失，需要把数据备份到本地存储
      setItem(TOKEN_KEY, state.user)
    }
  },
  actions: {},
  modules: {}
})
